package connection;

import java.io.IOException;
import java.io.Reader;


import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class DataAccess {
	private final static String resource = "mybatis.xml";
	private static SqlSessionFactory sqlSessionFactory = null;
	private DataAccess(){
	}
	private static SqlSessionFactory getSqlSessionFactory(){
		if(sqlSessionFactory == null){
			Reader reader = null;
			try {
				reader = Resources.getResourceAsReader(resource);
			} catch (IOException e) {
				e.printStackTrace();
			}
			sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
		}
		return sqlSessionFactory;
	}
	public static SqlSession getSqlSession(){
		return getSqlSessionFactory().openSession();
	}
}
